import itertools as it

def grouper(iterable, size, pad_value=None):
    """
    Slightly modified version of 
    http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks-in-python/312644#312644 
    which references 
    http://docs.python.org/library/itertools.html#itertools.izip

    >>> bob = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>> list(grouper(bob, 4))
    [(1, 2, 3, 4), (5, 6, 7, 8), (9, None, None, None)]
    """
    # Could use itertools.izip_longest if we were on python 2.6
    if iterable:
        return it.izip(
            *[it.chain(iterable, it.repeat(pad_value, size-1))]*size)
    else:
        return []


